﻿@using BonjourQuotation.UI.Models.PartialModel
@model OperationGirGroupPriceGridViewModel

<script type="text/javascript">
    // Gir Group Prices
    var GroupPricesGridModel;
    debugger;
    LoadGroupPricesGrid();

    function LoadGroupPricesGrid()
    {
        GroupPricesGridModel = $(@Html.Raw(Json.Encode(Model))).JSModel();
        var GrPrcolumnHeaders = [];
        var GrPrcolumns = [];
        var GrPrcolWidth = [];

        GrPrcolumnHeaders.push("Group Code");
        GrPrcolumns.push({ data: "PriceGroupCode", type: "text", readOnly: true });
        GrPrcolWidth.push(110);

        GrPrcolumnHeaders.push("Group Name");
        GrPrcolumns.push({ data: "PriceGroupName", type: "text", readOnly: true });
        GrPrcolWidth.push(200);

        GrPrcolumnHeaders.push("Arrival Date");
        GrPrcolumns.push({ data: "PriceArrivalDate", type: "text", readOnly: true });
        GrPrcolWidth.push(120);

        GrPrcolumnHeaders.push("Customer");
        GrPrcolumns.push({ data: "PriceCustomer", type: "text", readOnly: true });
        GrPrcolWidth.push(220);

        GrPrcolumnHeaders.push("Pr. P.P");
        GrPrcolumns.push({ data: "PricePricePerPerson", type: "numeric", format: '0,0.00' });
        GrPrcolWidth.push(70);

        GrPrcolumnHeaders.push("F. Board Pr.");
        GrPrcolumns.push({ data: "PricePriceFBoard", type: "numeric", format: '0,0.00' });
        GrPrcolWidth.push(90);

        GrPrcolumnHeaders.push("S. Sup");
        GrPrcolumns.push({ data: "PricePriceSingleSup", type: "numeric", format: '0,0.00' });
        GrPrcolWidth.push(70);

        GrPrcolumnHeaders.push("Pr. P.P Cad");
        GrPrcolumns.push({ data: "PricePricePerPersonCad", type: "numeric", format: '0,0.00' });
        GrPrcolWidth.push(90);

        GrPrcolumnHeaders.push("F. Board Pr. Cad");
        GrPrcolumns.push({ data: "PricePriceFBoardCad", type: "numeric", format: '0,0.00' });
        GrPrcolWidth.push(90);

        GrPrcolumnHeaders.push("S. Sup Cad");
        GrPrcolumns.push({ data: "PricePriceSingleSupCad", type: "numeric", format: '0,0.00' });
        GrPrcolWidth.push(80);

        GirPriceRedColorRendererForNegative = function (instance, td, row, col, prop, value, cellProperties) {
            Handsontable.renderers.NumericRenderer.apply(this, arguments);
            td.style.color = 'red';
        };

        var Pricedata = GroupPricesGridModel[0].Rows;
        $('#OperGirGroupPriceGrid').handsontable({
            data: Pricedata,
            minSpareRows: 0,
            colHeaders: GrPrcolumnHeaders,
            colWidths: GrPrcolWidth,
            contextMenu: false,
            manualColumnResize: true,
            manualRowResize: true,
            columns: GrPrcolumns,
            cells: function (row, col) {
                var Cellinstance = this;
                if (Cellinstance.renderer == Handsontable.renderers.NumericRenderer && Cellinstance.instance.getDataAtCell(row, col) < 0) {
                    Cellinstance.renderer = GirPriceRedColorRendererForNegative;
                }
            }
        });
    }
    function OperationSaveGirGroupPrices()
    {
        var Rows = $('#OperGirGroupPriceGrid').data('handsontable').getData();
        var OperationGirGroupPriceGridViewModel = {
            Rows: Rows,
        };

        var DTO = JSON.stringify(OperationGirGroupPriceGridViewModel);

        $.ajax({
            url: urls["OperationSaveGirGroupPrices"],
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: DTO,
            success: function (data) {
                $("#RoomGridUpSearch").click();
                $("#cboxClose").click();
                
               // $("#GirGroupPricesDiv").html(data);
            },
            error: function (xhr) {
                //   alert('Error: ' + xhr.statusText);
            },
            complete: function () {
                //  $("#LoadingDiv").hide();
            }
        });
    }
</script>
<div style="padding-top:20px; padding-left:6px;">
    @if(Model.Error != null)
    {
        @Html.LabelForModel(Model.Error)
    }
    <div id="OperGirGroupPriceGrid" class="handsontable" style="width: 1185px; height:240px; overflow:auto;">
    </div>
    
    <div>
        <input type="submit" class="btn14 btn60 pull-right" style="margin-right:10px;" onclick="OperationSaveGirGroupPrices()" value="Save">
    </div>
</div>






